package com.hd123.rumba.qt.def;

import java.util.ArrayList;
import java.util.List;

import com.hd123.rumba.exception.BusinessException;

public class SQLJoinList extends ArrayList implements List {
  public String getSQLClause() throws BusinessException {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < size(); ++i) {
      SQLJoin item = (SQLJoin) get(i);
      String s = item.getSQLWhereExpression();
      if (s != null) {
        if (sb.length() > 0)
          sb.append(" and ");
        sb.append(" (");
        sb.append(s);
        sb.append(") ");
      }
    }
    return sb.length() == 0 ? null : sb.toString();
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    for (int i = 0; i < size(); ++i) {
      SQLJoin item = (SQLJoin) get(i);
      sb.append(i + ": " + item.debugInfo() + "\n");
    }
    return sb.toString();
  }

}
